package org.rssReader;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.rssReader.utils.TextTransfer;


public class LinksParser {
	
	public static TextTransfer textTransfer = new TextTransfer();

	
	public LinksParser() {}
	public static void main(String[] args){
		System.out.println(getLinks(args[0], args[1]).toString());
	}
//	
	/**
	 * Gets A string with a lot of links in it,parse it and returns a list of links
	 * for the desired server
	 * <br><b> In addition  - copy the links to the clipboard</b>
	 * @param regex - the regex to check in the string
	 * @param description - the description tag in the rss bean that holds all the links
	 * @return list of the links for the desired server
	 */
	static public List<String> getLinks(String regex,String description){
		List<String> links = new ArrayList<String>();
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(description);
		StringBuilder sb = new StringBuilder();
		while(m.find()){
			links.add(m.group());
//			System.out.println(m.group());
			sb.append(m.group()+ "\n");
		}
		textTransfer.setClipboardContents(sb.toString());
		return links;

		
	}
}